﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI.WebControls;
using EasyBuildingCMS.BLL.CoreEngine;

namespace EasyBuildingCMS.UserControls.Core.Utility
{
    public class EBCMenu:Menu
    {
        private int selectedMenuItemLevel = 0;
        public int SelectedMenuItemLevel 
        {
            get { return selectedMenuItemLevel; }
            set { selectedMenuItemLevel = value; }
        }

        public EBCMenu()
        {
            this.DataBound += new System.EventHandler(this.EBC_DataBound);
        
        }

        protected void EBC_DataBound(object sender, EventArgs e)
        {
            int? currentPageID = BLL.Helper.ToInt(BLL.Globals.CurrentPage);

            PageRepository pageRepository = new PageRepository();
            List<string> navigationTextPath = pageRepository.GetCurrentPageNavigationTextPath((int)currentPageID);

            if (navigationTextPath.Count < SelectedMenuItemLevel + 1)
                return;

            if (this.Items.Count > 0)
                this.FindItem(navigationTextPath[SelectedMenuItemLevel]).Selected = true;
        }
    }
}